//index.js
const app = getApp()

 const Api = require("../../utils/api.js").API
 const Store = require("../../utils/store.js").store

Page({
  data: {
   option1: [
       
         { text: '专用增值税发票', value: '111501' },
         { text: '普通增值税发票', value: '111502' },
       ],
        value1: 0,
        clickQ1:true,
         clickQ2:false,
         checkedMo:false,
         clickDL:false,
         clickMX:true,
         isChange:false,
          value: '',
          
          list:{
	"addr": "",
	"area": "",
	"bankCardNum": "",
	"bankName": "",
	"batchNo": "",
	"city": "",
	"email": "",
	"invoiceCategory": "111701",
	"invoiceName": "",
	"invoiceTitle": "111601",
	"invoiceType": "111501",
	"phone": "",
	"province": "",
	"taxpaperIdNum": "",
    'invoiceAmount':'',
    
    
}
  
 
  },
  onLoad(){
      
      let that = this;
      var bean = {};
      const eventChannel = this.getOpenerEventChannel();
      eventChannel.on('acceptDataFromOpenerPage', function(data) {
          bean = data.data;
          Api.batchNoCheakApi(bean.a).then(res=>{
              if(res.code == 0 && res.invoiceinfo){
                 if(res.invoiceinfo.invoiceCategory  == '111702'){
                     that.setData({
                         clickDL:true,
                         clickMX:false
                     })
                 }
                 if(res.invoiceinfo.invoiceTitle  == '111602'){
                     that.setData({
                         clickQ1:false,
                         clickQ2:true
                     })
                 }
                 
                  that.setData({
                      
                      ["list.addr"]:res.invoiceinfo.addr,
                       ["list.bankName"]:res.invoiceinfo.bankName,
                      ["list.area"]:res.invoiceinfo.area,
                      ["list.bankCardNum"]:res.invoiceinfo.bankCardNum,
                      ["list.batchNo"]:res.invoiceinfo.batchNo,
                      ["list.city"]:res.invoiceinfo.city,
                      ["list.email"]:res.invoiceinfo.email,
                      ["list.invoiceCategory"]:res.invoiceinfo.invoiceCategory,
                      ["list.invoiceName"]:res.invoiceinfo.invoiceName,
                      ["list.invoiceTitle"]:res.invoiceinfo.invoiceTitle,
                      ["list.invoiceType"]:res.invoiceinfo.invoiceType,
                      ["list.phone"]:res.invoiceinfo.phone,
                      ["list.province"]:res.invoiceinfo.province,
                      ["list.taxpaperIdNum"]:res.invoiceinfo.taxpaperIdNum,
                      ["list.invoiceAmount"]:res.invoiceinfo.invoiceAmount,
                      isChange:true,
                  })
              }
          })
         
      
          that.setData({
              ['list.batchNo']:bean.a,
              ['list.invoiceAmount']:bean.b
          })
      
      })
      
   },
   onSwitch1Change(e){
       console.log(e)
       this.setData({
            ['list.invoiceType']:e.detail
       })
      
   },
   clickZhi(e){
       
       if(e.detail == true){
           this.setData({
               ['list.invoiceTitle']:'111601',
               clickQ1:e.detail,
               clickQ2:!e.detail
               
           })
       }
      
   },
   clickZhi2:function(e){
       if(e.detail == true){
           this.setData({
               ['list.invoiceTitle']:'111602',
               clickQ2:e.detail,
               clickQ1:!e.detail
               
           })
       }
   },
   clickDL(e){
       
       if(e.detail == true){
           this.setData({
                ['list.invoiceCategory']:'111702',
               clickDL:e.detail,
               clickMX:!e.detail
               
           })
       }
      
   },
   clickMX:function(e){
       if(e.detail == true){
           this.setData({
                 ['list.invoiceCategory']:'111701',
               clickMX:e.detail,
                clickDL:!e.detail
               
           })
       }
   },
   onChangeM(e){
       this.setData({
             checkedMo: e.detail,
       });
   },
   
   commitSu:function(){
        let data = this.data.list;
       if(this.data.isChange){
           Api.FaPiaoChangeApi(data).then(res=>{
               
               wx.navigateBack()
           })
       }else{
           Api.invoiceinfoApi(data).then(res=>{
               
               wx.navigateBack()
           })
       }
     
       
      
    
   },
   invoiceName(event) {
       // event.detail 为当前输入的值
       console.log(event.detail);
       this.setData({
   
           [`list.invoiceName`]: event.detail,
       });
   },
   taxpaperIdNum(event){
       console.log(event.detail);
       this.setData({
          
           [`list.taxpaperIdNum`]: event.detail,
       });
   },
   bankName(event){
       console.log(event.detail);
       this.setData({
          
           [`list.bankName`]: event.detail,
       });
   },
   bankCardNum(event){
       console.log(event.detail);
       this.setData({
          
           [`list.bankCardNum`]: event.detail,
       });
   },
   phone(event){
       console.log(event.detail);
       this.setData({
          
           [`list.phone`]: event.detail,
       });
   },
   addr(event){
       console.log(event.detail);
       this.setData({
          
           [`list.addr`]: event.detail,
       });
   },
   
   })